package com.itheima.controller;

import com.itheima.domain.LoginInfo;
import com.itheima.domain.Result;
import com.itheima.domain.pojo.Emp;
import com.itheima.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@Slf4j
public class LoginController {

    @Autowired
    private EmpService empService;

    /**
     * 登录功能
     * @param loginInfoMap
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody Map<String, Object> loginInfoMap) {
        log.info("用户登录:{}", loginInfoMap);
        LoginInfo loginInfo = empService.login(loginInfoMap);
        if(loginInfo == null) {
            return Result.error("用户名或密码错误");
        }
        return Result.success(loginInfo);
    }
}
